/*
 * Copyright (c) gitee.com/jiandong001.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import hilog from '@ohos.hilog';
import Context from '@ohos.application.context';
import { ReactContext } from '../bridge/ReactContext';

export class PackagerConnectionSettings {
  private static readonly TAG = "React PackagerConnectionSettings";
  private static readonly PREFS_DEBUG_SERVER_HOST_KEY = "debug_http_host";

//  private readonly mPreferences: SharedPreferences;
  private readonly mPackageName: string;
  private readonly mAbilityContext: Context.AbilityContext; //context

  public constructor(abilityContext: Context.AbilityContext) {

    hilog.info(0x0000, PackagerConnectionSettings.TAG, 'constructor');

//  this.mPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext);
    this.mAbilityContext = abilityContext;
    this.mPackageName = abilityContext.abilityInfo.bundleName//getPackageName();


    hilog.info(0x0000, PackagerConnectionSettings.TAG, 'constructor 222222' + "bundle name: " +
      this.mPackageName, "Ability  name: " + abilityContext.abilityInfo.name);

}

public getDebugServerHost(): string {
//    // Check host setting first. If empty try to detect emulator type and use default
//    // hostname for those
//    String hostFromSettings = mPreferences.getString(PREFS_DEBUG_SERVER_HOST_KEY, null);
//
//    if (!TextUtils.isEmpty(hostFromSettings)) {
//      return Assertions.assertNotNull(hostFromSettings);
//    }
//
//String host = AndroidInfoHelpers.getServerHost(mAppContext);
//
//if (host.equals(AndroidInfoHelpers.DEVICE_LOCALHOST)) {
//  FLog.w(
//    TAG,
//    "You seem to be running on device. Run '"
//    + AndroidInfoHelpers.getAdbReverseTcpCommand(mAppContext)
//    + "' "
//    + "to forward the debug server's port to the device.");
//}
//
//return host;
  return "localhost:8081"
}

public setDebugServerHost(host: string): void {
  //mPreferences.edit().putString(PREFS_DEBUG_SERVER_HOST_KEY, host).apply();
}

public getInspectorServerHost(): string {
  return ""
//  return AndroidInfoHelpers.getInspectorProxyHost(mAppContext);
}

public getPackageName(): string | null {
  return this.mPackageName;
}
}
